import { Ref, ref, watchEffect } from 'vue'

export const useStorage = <T>(name: string, value:T) => {
    const data: Ref<T> = ref(JSON.parse(localStorage.getItem(name) || '') || value || [])
    
    watchEffect(() => {
        window.localStorage.setItem(name, JSON.stringify(data.value))
    })

    return {
        data
    }
}